********************************************************************************
* Table 4. REVENUES AND EXPENDITURES ESTIMATES
********************************************************************************
clear
use "$data/fdiff.dta", clear
set more off

global y3 	totrev_all_res_d
global y4 	totexp_all_res_d
global y5 	totrev_excl_res_d
global y6 	totexp_excl_res_d

* All budget & using population in t-1

	// Revenues
qui ivreg2 $y3 ($x = $z) i.year [aw=$w], robust first small
	estimates store iv1, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

qui ivreg2 $y3 ($x = $z) $ctrl i.year [aw=$w], robust first small
	estimates store iv2, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl "Yes"
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

qui ivreg2 $y3 ($x = $z) $ctrlxyear i.year [aw=$w], robust first small
	estimates store iv3, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear "Yes"
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)
	
	// Expenditures
qui ivreg2 $y4 ($x = $z) i.year [aw=$w], robust first small
	estimates store iv4, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)
	
qui ivreg2 $y4 ($x = $z) $ctrl i.year [aw=$w], robust first small
	estimates store iv5, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl "Yes"
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

qui ivreg2 $y4 ($x = $z) $ctrlxyear i.year [aw=$w], robust first small
	estimates store iv6, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear "Yes"
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

	// Tabulate results
esttab iv1 iv2 iv3 iv4 iv5 iv6,  keep($x) ///
star(* 0.10 ** 0.05 *** 0.01)  b(3) se(3)  ///
coeflabels($x "Immigrant inflows") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("Fstat Kleibergen-Paap F" "ARtest Anderson-Rubin test" ///
"year_fe Year FE" "ctrl MSA-level controls" "ctrlxyear Controls x Year FE") ///
title("All budget") 


* Restricted budget & using population in t-1

		// Revenues
qui ivreg2 $y5 ($x = $z) i.year [aw=$w], robust first small
	estimates store iv1, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)
	
qui ivreg2 $y5 ($x = $z) $ctrl i.year [aw=$w], robust first small
	estimates store iv2, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl "Yes"
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

qui ivreg2 $y5 ($x = $z) $ctrlxyear i.year [aw=$w], robust first small
	estimates store iv3, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear "Yes"
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)
	
	// Expenditures
qui ivreg2 $y6 ($x = $z) i.year [aw=$w], robust first small
	estimates store iv4, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

qui ivreg2 $y6 ($x = $z) $ctrl i.year [aw=$w], robust first small
	estimates store iv5, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl "Yes"
	estadd local ctrlxyear ""
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

qui ivreg2 $y6 ($x = $z) $ctrlxyear i.year [aw=$w], robust first small
	estimates store iv6, title (2SLS-2005)
	estadd local year_fe "Yes"
	estadd local ctrl ""
	estadd local ctrlxyear "Yes"
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar ARtest = e(arfp)

	// Tabulate results
esttab iv1 iv2 iv3 iv4 iv5 iv6,  keep($x) ///
star(* 0.10 ** 0.05 *** 0.01)  b(3) se(3)  ///
coeflabels($x "Immigrant inflows") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("Fstat Kleibergen-Paap F" "ARtest Anderson-Rubin test" ///
"year_fe Year FE" "ctrl MSA-level controls" "ctrlxyear Controls x Year FE") ///
title("Restrictive budget") 
